package com.zhu.service.edu.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.zhu.commons.utils.BeanCopyUtils;
import com.zhu.service.edu.listener.ExcelSubjectDataListener;
import com.zhu.service.edu.pojo.EduSubject;
import com.zhu.service.edu.mapper.EduSubjectMapper;
import com.zhu.service.edu.pojo.excel.ExcelSubjectData;
import com.zhu.service.edu.pojo.vo.SubjectVo;
import com.zhu.service.edu.service.IEduSubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

/**
 * <p>
 * 课程科目 服务实现类
 * </p>
 *
 * @author zhu
 * @since 2022-07-04
 */
@Service
public class EduSubjectServiceImpl extends ServiceImpl<EduSubjectMapper, EduSubject> implements IEduSubjectService {
    @Autowired
    private EduSubjectMapper subjectMapper;
    /**
     * 批量导入excel信息
     * @param inputStream
     */
    @Override
    public void batchImport(InputStream inputStream) {
        EasyExcel.read(inputStream, ExcelSubjectData.class,new ExcelSubjectDataListener(subjectMapper))
                .excelType(ExcelTypeEnum.XLS)
                .sheet().doRead();
    }

    @Override
    public List<SubjectVo> nestedList() {
         List<EduSubject>  subjectList= subjectMapper.selectNestedList();
        List<SubjectVo> subjectVos = BeanCopyUtils.copyBeanList(subjectList, SubjectVo.class);
        return subjectVos;
    }
}
